package com.example.lenovo_.healthyangel_home;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.example.lenovo_.healthyangel.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lenovo- on 2016/10/22.
 */

@TargetApi(Build.VERSION_CODES.M)
public class HealthysportLietviewActivity extends AppCompatActivity implements AdapterView.OnItemClickListener,AbsListView.OnScrollListener{
    private ListView listview;
//    private ArrayAdapter<String> arrayAdapter;
    private SimpleAdapter simple_Adapter;
    private List<Map<String,Object>>datalist;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_healthysport_listview);
        listview= (ListView) findViewById(R.id.listview1);
//        String[] arrdata={"傻逼0","傻逼1","傻逼2","傻逼3","傻逼4","傻逼5","傻逼6"};
        datalist=new ArrayList<Map<String,Object>>();
//        arrayAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arrdata);
//        listview.setAdapter(arrayAdapter);
        simple_Adapter=new SimpleAdapter(this, getData1(),R.layout.home_healthysport_horizonal_item,new String[]{"pic","text"},new int[]{R.id.imageView6,R.id.textView10});
        listview.setAdapter(simple_Adapter);
        listview.setOnItemClickListener(this);
        listview.setOnScrollListener((AbsListView.OnScrollListener) this);
    }

    private List<Map<String,Object>> getData1() {
            for (int i=0;i<20;i++){
                Map<String,Object> map=new HashMap<String, Object>();
                map.put("pic",R.mipmap.ic_launcher);
                map.put("text","傻逼"+(i+1));
                datalist.add(map);
            }
        return datalist;
    }
/**
 * 以下为点击每一个item时产生的事件
 */
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    }

    /**
     *以下为滚动时产生的变化
     */

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        switch (scrollState)
        {
            case SCROLL_STATE_FLING:
                Map<String,Object>map=new HashMap<String,Object>();
                map.put("pic",R.mipmap.cabbage);
                map.put("text","陈瑞是智障");
                datalist.add(map);
                simple_Adapter.notifyDataSetChanged();
                break;
            case SCROLL_STATE_IDLE:
                break;
            case SCROLL_STATE_TOUCH_SCROLL:
                break;
        }

    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

    }
}
